package com.example.service.impl;

import com.example.entity.Role;
import com.example.mapper.RoleMapper;
import com.example.service.RoleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public Role getRoleWithMenusById(Integer roleId) {
        Map<String, Object> params = new HashMap<>();
        params.put("roleId", roleId);
        return roleMapper.selectRoleWithMenus(params);
    }

    @Override
    public Role getRoleWithMenusByName(String roleName) {
        Map<String, Object> params = new HashMap<>();
        params.put("roleName", roleName);
        return roleMapper.selectRoleWithMenus(params);
    }

    @Override
    public Page<Role> getRolesWithMenus(Map<String, Object> params, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return roleMapper.selectRolesWithMenus(params);
    }
}